/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.mycompany.psc.controllers;

import com.mycompany.psc.ejb.ReportableItemsManager;
import com.mycompany.psc.entities.MetalDoors;
import com.mycompany.psc.entities.MetalDoorsOffers;
import com.mycompany.psc.entities.Users;
import com.mycompany.psc.producers.LoggedIn;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.ejb.EJB;
import javax.enterprise.context.SessionScoped;
import javax.inject.Inject;
import javax.inject.Named;

/**
 *
 * @author A7med
 */
@Named
@SessionScoped
public class SteelController implements Serializable{
    @EJB
    ReportableItemsManager rm;
    @Inject
    ProjectsBean p;
    private String title;
    private String code;
    @Inject
    @LoggedIn
    Users current;
    private MetalDoors selectedResource;
    private MetalDoorsOffers newItem=new MetalDoorsOffers();
     private float rate;
    private int amount;
    private String discription;
    private MetalDoorsOffers editableItem;

    public String getDiscription() {
        return discription;
    }

    public void setDiscription(String discription) {
        this.discription = discription;
    }

    public MetalDoorsOffers getEditableItem() {
        return editableItem;
    }

    public void setEditableItem(MetalDoorsOffers editableItem) {
        this.editableItem = editableItem;
    }
    private String dimension;

    public String getTitle() {
        return title;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public MetalDoors getSelectedResource() {
        return selectedResource;
    }

    public void setSelectedResource(MetalDoors selectedResource) {
        this.selectedResource = selectedResource;
    }

    public MetalDoorsOffers getNewItem() {
        return newItem;
    }

    public void setNewItem(MetalDoorsOffers newItem) {
        this.newItem = newItem;
    }

    public float getRate() {
        return rate;
    }

    public void setRate(float rate) {
        this.rate = rate;
    }

    public int getAmount() {
        return amount;
    }

    public void setAmount(int amount) {
        this.amount = amount;
    }

    

    public String getDimension() {
        return dimension;
    }

    public void setDimension(String dimension) {
        this.dimension = dimension;
    }
     public void save() {
         MetalDoors t=new MetalDoors();
        t.setAuthor(current.getName());
        t.setProjectId(p.getSelectedReportProject());
        t.setSubmitDate(new Date());
        t.setDimension(dimension);
        t.setQuantity(amount);
        t.setRate(rate);
        t.setDiscription(discription);
        t.setCode(code);
        t.setTitle(title);
        rm.persistObject(t);
    }
     public void saveData(){
        newItem.setParent(getSelectedResource());
        getSelectedResource().getMetalDoorsOffersList().add(newItem);
        
        rm.update(getSelectedResource());
    }
      public List<MetalDoors> getSteelResources() {
        return rm.getSteelDoorsResources(p.getSelectedReportProject());
    }
        public List<MetalDoorsOffers> getChildResources() {
        List<MetalDoors> list = rm.getSteelDoorsResources(p.getSelectedReportProject());
        List<MetalDoorsOffers> out=new ArrayList<>();
        for(MetalDoors ti:list){
            out.addAll(ti.getMetalDoorsOffersList());
        }
        return out;
    }
 public void updateItem(){
        rm.update(selectedResource);
    }
    public void updateChildItem(){
        rm.update(editableItem);
    }
}
